<html>
<head>
    <meta charset="utf-8">
    <title>变量、作用域</title>

</head>
<body>
<button>1</button>
<button>2</button>
<button>3</button>
<script type="text/javascript">
    var btns = document.getElementsByTagName('button');
    for (var i = 0; i < btns.length; i++) {
        (function (i) {
            btns[i].onclick = function () {
                alert(i+1);
            };
        })(i);

    };
</script>
</body>
</html>